package net_UDP;

import java.io.IOException;
import java.net.SocketException;
import java.util.HashMap;
import java.util.Map;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: qian
 * Date: 2023-02-18
 * Time: 17:33
 */
//翻译服务器
public class UdpTranslateServer extends UdpEchoServer{
    //创建一个哈希表存放词组
    private Map<String,String> dict=new HashMap<>();
    public UdpTranslateServer(int port) throws SocketException {
        super(port);
        dict.put("cat","小猫");
        dict.put("dog","小狗");
        dict.put("duck","鸭子");

    }
    //重写process方法，实现英译汉功能

    @Override
    public String process(String request) {
        return dict.getOrDefault(request,"在词典中未找到");
    }

    public static void main(String[] args) throws IOException {
        UdpTranslateServer translateServer=new UdpTranslateServer(9090);
        translateServer.start();
    }
}
